import Taro from "@tarojs/taro";
import { FabricObject } from "fabric";

export type SVGParsingOutput = {
    objects: (FabricObject | null)[];
    options: Record<string, any>;
    elements: Element[];
    allElements: Element[];
};

export default async function loadSVGFromURL(
    url: string,
    // reviver?: TSvgReviverCallback,
    // options: LoadImageOptions = {},
): Promise<SVGParsingOutput> {

    return new Promise<SVGParsingOutput>((resolve, reject) => {
        Taro.request({
            url,
            success: (svgText) => {
                console.log("svgText.data", svgText.data);
                resolve(loadSVGFromString(svgText.data));
            },
            fail: (error) => {
                console.log("请求失败", url);
                resolve({
                    objects: [],
                    elements: [],
                    options: {},
                    allElements: [],
                });
            }
        });

    })
 
}


export async function loadSVGFromString(
    string: string,
    // reviver?: TSvgReviverCallback,
    // options?: LoadImageOptions,
): Promise<SVGParsingOutput> {

    return {
        objects: [],
        elements: [],
        options: {},
        allElements: [],
    }

    // const parser = new (getFabricWindow().DOMParser)(),
    //     // should we use `image/svg+xml` here?
    //     doc = parser.parseFromString(string.trim(), 'text/xml');
    // return parseSVGDocument(doc, reviver, options);
}